import request from '@/utils/request'
import type { ResponseData } from '@/types/common'
import type { Package, PackageQuery } from '@/types/package'

// 获取套餐列表
export const getPackageList = (params?: {
  keyword?: string
  minPrice?: number
  maxPrice?: number
  page?: number
  pageSize?: number
  photographer_level?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Package[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('/packages/list', {
    params: {
      keyword: params?.keyword || '',
      minPrice: params?.minPrice,
      maxPrice: params?.maxPrice,
      page: params?.page || 1,
      pageSize: params?.pageSize || 10,
      photographer_level: params?.photographer_level,
    },
  })
}

export const getPackages = () => {
  return request.get<{
    result: Package[]
    message: string
  }>('/packages')
}

// 创建套餐
export const createPackage = (data: {
  name: string
  description: string
  photos: string[]
  price: number
  original_price: number
  photographer_level: number
  deposit: number
  package_gift: string[]
  team_service: string[]
  image_product: string[]
  tips: string[]
  sort_order: number
}) => {
  return request.post<ResponseData>('/packages', data)
}

// 获取套餐详情
export const getPackageDetail = (id: number) => {
  return request.get<{
    code: number
    data: Package
    message: string
  }>(`/packages/${id}/detail`)
}

// 更新套餐信息
export const updatePackage = (
  id: number,
  data: {
    name?: string
    description?: string
    cover_image?: string
    photos?: string[]
    price?: number
    original_price?: number
    deposit?: number
    photographer_level?: number
    package_gift?: string[]
    team_service?: string[]
    image_product?: string[]
    tips?: string[]
    sort_order?: number
  },
) => {
  return request.patch<ResponseData>(`/packages/${id}/update`, data)
}

// 更新套餐照片
export const updatePackagePhotos = (id: number, data: { photos: string[] }) => {
  return request.patch<ResponseData>(`/packages/${id}/photos`, data)
}

// 切换套餐状态(上架/下架)
export const updatePackageStatus = (id: number) => {
  return request.patch<ResponseData>(`/packages/${id}/status`)
}

// 更新套餐排序
export const updatePackageSort = (id: number, sort_order: number) => {
  return request.patch<ResponseData>(`/packages/${id}/sort`, { sort_order })
}

// 删除套餐
export const deletePackage = (id: number) => {
  return request.delete<ResponseData>(`/packages/${id}`)
}
